#pragma once

#include <engine.core/math.hpp>
#include "Glyph.hpp"




struct GlyphPlacement
{
	AdvancedGlyph*   glyph;
	int2             pos;
	intsize2         size;
	intsize2         actualSize;

	GlyphPlacement(AdvancedGlyph& glyph)
		: glyph(&glyph)
		, pos(-1, -1)
		, size(glyph.size() + intsize2(2, 2))
	{}
};
///////////////////////////////////////////////////////////////////////////////////////////////////




class Atlas
{
public:

	typedef std::vector<GlyphPlacement>   GlyphPlacements;
	typedef QSet<AdvancedGlyph*>          Glyphs;

private:

	QImage            m_image;

	GlyphPlacements   m_glyphs;
	Glyphs            m_placedGlyphs;

	intsize2          m_size;

public:

	/**
	 * Constructs an Atlas.
	 *
	 * @param	textureFilenames	The filenames of the textures to load into this atlas.
	 */
	Atlas(const GlyphPlacements& glyphs);



	/**
	 * Retrieve the created image.
	 */
	QImage image() const;

private:

	void calculateDimensions();
	void pack();
	void fill(int x1, int y1, int x2, int y2, int& count);
	void paint();
};
///////////////////////////////////////////////////////////////////////////////////////////////////
